package com.hpeng.sys.dao.impl;

import java.util.List;

import org.springframework.stereotype.Component;

import com.hpeng.sys.dao.AssetCardsDao;
import com.hpeng.sys.dao.CategorysDao;
import com.hpeng.sys.model.AssetCard;
import com.hpeng.sys.model.Category;
import com.hpeng.sys.model.ProdStatusMst;
import com.hpeng.util.GenericDaoImpl;

@Component("assetCardsDao")  
public class AssetCardsDaoImpl extends GenericDaoImpl<AssetCard,String> implements AssetCardsDao{
	public List<AssetCard> getInuseAssetCardByCatId(String catId){
		System.out.println(catId);
		List<AssetCard> assetCards = null;
		assetCards = getByHql("from AssetCard assetCard where assetCard.category like '"+catId+"%' and assetCard.acstatus='400'");
		System.out.println(assetCards.size());
		return assetCards;
	}
	public List<AssetCard> getByDepName(String depName){
		System.out.println(depName);
		List<AssetCard> assetCard = null;
		if(depName.equals("")){
			assetCard = getByHql("from AssetCard assetCard where assetCard.acstatus='400'");
		}else{
			assetCard = getByHql("from AssetCard assetCard where assetCard.depname = '"+depName+"' and assetCard.acstatus='400'");
		}
		System.out.println(assetCard.size());
		return assetCard;
	}
	public List<AssetCard> getByAccountSubject(String accountSubject){
		System.out.println(accountSubject);
		List<AssetCard> assetCard = null;
		if(accountSubject.equals("")){
			assetCard = getByHql("from AssetCard assetCard where assetCard.acstatus='400'");
		}else{
			assetCard = getByHql("from AssetCard assetCard where assetCard.accountsubject = '"+accountSubject+"' and assetCard.acstatus='400'");
		}
		System.out.println(assetCard.size());
		return assetCard;
	}
	public List<AssetCard> getByCatid(String catid){
		List<AssetCard> assetCard = null;
		assetCard = getByHql("from AssetCard assetCard where assetCard.category like '"+catid+"' and assetCard.acstatus='1%'");
		return assetCard;
	}
	public List<AssetCard> getByDepAndStatus(String depName,String[] status){
		List<AssetCard> assetCard = null;
		String hql = "from AssetCard assetCard where (";
		for(int i = 0; i < status.length;i++){
			if(i!=0){
				hql += " or ";
			}
			hql += "assetCard.acstatus like '_"+status[i]+"'";
		}
		hql += ")";
		hql +=  " and assetCard.reportdepartment = '"+depName+"'";
		System.out.println(hql);
		assetCard = getByHql(hql);
		return assetCard;
	}
	public AssetCard getByAssetCardId(String id){
		return get(id);
	}
	public boolean UpdateStatus(String assetCardIds,ProdStatusMst prodStatus){
		AssetCard assetCard = get(assetCardIds);
		System.out.println(prodStatus.getStatuscode()+prodStatus.getSubcode());
		assetCard.setAcstatus(prodStatus.getStatuscode()+prodStatus.getSubcode());
		update(assetCard);
		return true;
	}
}